package com.jack.leetcode.eachproblem_2020;

public class 柠檬水找零 {

    public static void main(String[] args) {
        int[] a = {5,5,10,20,5,5,5,5,5,5,5,5,5,10,5,5,20,5,20,5};
        System.out.println(lemonadeChange(a));
        int[] b = {5,5,10,10,20};
        System.out.println(lemonadeChange(b));
    }

    public static boolean lemonadeChange(int[] bills) {
        int n = bills.length;
        if(n == 0){
            return true;
        }
        if(bills[0] != 5){
            return false;
        }
        int[] count = new int[2];
        for(int i : bills){
            switch (i){
                case 5:
                    count[0]++;
                    break;
                case 10:
                    if(count[0] == 0){
                        return false;
                    }
                    count[0]--;
                    count[1]++;
                    break;
                case 20:
                    if(count[0] > 0 && count[1] > 0){
                        count[0]--;
                        count[1]--;
                        break;
                    }
                    if(count[0] >= 3 && count[1] == 0){
                        count[0]-=3;
                        break;
                    }
                    return false;
            }
        }
        return true;
    }
}
